#pragma once

#include <QString>
#include <QDateTime>
#include <QVariantMap>

namespace TCServer
{
	namespace Type
	{
		class News
		{
		public:
			quint64 id;
			QDateTime time;
			quint64 groupId;
			QString iconTitle;
			QString iconColor;
			QString title;
			QString author;
			QString contentUrl;
			bool operator == (const News &rhs) const
			{
				return groupId == rhs.groupId
					&& iconTitle == rhs.iconTitle
					//&& iconColor == rhs.iconColor
					&& title == rhs.title
					&& author == rhs.author
					&& contentUrl == rhs.contentUrl;
			}

			static News fromVariantMap(const QVariantMap &args)
			{
				News val;
				if (args.count("id"))
					val.id = args.value("id").toULongLong();
				if (args.count("time"))
					val.time = args.value("time").toDateTime();
				val.groupId = args.value("groupId").toULongLong();
				val.iconTitle = args.value("iconTitle").toString();
				val.iconColor = args.value("iconColor").toString();
				val.title = args.value("title").toString();
				val.author = args.value("author").toString();
				val.contentUrl = args.value("contentUrl").toString();
				return std::move(val);
			}

			QVariantMap toVairantMap() const
			{
				return QVariantMap {
					{ "id", id },
					{ "time", time },
					{ "groupId", groupId },
					{ "iconTitle", iconTitle },
					{ "iconColor", iconColor },
					{ "title", title },
					{ "author", author },
					{ "contentUrl", contentUrl },
				};
			}
		};
	}
}